package com.hu.zhcc.shiro.controller;

import com.hu.zhcc.shiro.entity.tj.THealthPlan;
import com.hu.zhcc.shiro.entity.tj.THealthPlanType;
import com.hu.zhcc.shiro.service.Tj_THealthPlanService;
import com.hu.zhcc.shiro.service.Tj_THealthPlanTypeService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/tjthealthplan")
public class TjThealthPlanController {
    @Autowired
    private Tj_THealthPlanService tj_tHealthPlanService;//健康方案
    @Autowired
    private Tj_THealthPlanTypeService tjTHealthPlanTypeService;//健康类型
    //连接查询方案类型表
    @GetMapping("/all")
    public List<THealthPlan> queryAll(){
       return tj_tHealthPlanService.queryAll();
    }
    //查询方案类型
    @GetMapping("/allType")
    public List<THealthPlanType> queryAllPlanType(){
       return tjTHealthPlanTypeService.queryAll();
    }
    //模糊查询健康方案的标题 和健康类型表的id'
    @GetMapping("")
    public List<THealthPlan> queryLike(THealthPlan tHealthPlan){
        System.out.println(tHealthPlan);
      return   tj_tHealthPlanService.queryLike(tHealthPlan);
    }
    //添加数据
    @PostMapping("")
    public int addPlan(@RequestBody THealthPlan tHealthPlan){
     return  tj_tHealthPlanService.addPlan(tHealthPlan);
    }
    //删除健康方案
    @DeleteMapping("/{id}")
    public int delPlan(@PathVariable("id")Integer id){
        int i = tj_tHealthPlanService.delPlan(id);
        return i;
    }
    //根据编号查询
    @GetMapping("/{id}")
    public THealthPlan queryById(@PathVariable("id") Integer id){
       return tj_tHealthPlanService.queryById(id);
    }
    //修改
    @PutMapping("")
    public int updPlan(@RequestBody THealthPlan tHealthPlan){
      return   tj_tHealthPlanService.updPlan(tHealthPlan);
    }
}
